package csu.web.mypetstore.persistence.impl;

import csu.web.mypetstore.domain.Item;
import csu.web.mypetstore.domain.Product;
import csu.web.mypetstore.persistence.CategoryDao;
import csu.web.mypetstore.persistence.ItemDao;
import csu.web.mypetstore.persistence.ProductDao;
import csu.web.mypetstore.persistence.SearchDao;

import java.util.ArrayList;
import java.util.List;

public class SearchDaoImpl implements SearchDao {
    private CategoryDao categoryDao;
    private ProductDao productDao;
    private ItemDao itemDao;


    public SearchDaoImpl(){
        this.categoryDao = new CategoryDaoImpl();
        this.itemDao = new ItemDaoImpl();
        this.productDao = new ProductDaoImpl();
    }

    @Override
    public List<Item> searchItemListByProductName(String productName) {
        System.out.println(productName);
        List<Product> productList=productDao.searchProductListByProductName(productName);
        for(Product p:productList){
            System.out.println(p.getName());
        }
        List<Item> itemList=new ArrayList<Item>();
        for(Product product:productList){
            List<Item> itemListTemp=itemDao.getItemListByProductId(product.getProductId());
            for(Item item:itemListTemp){
                itemList.add(item);
            }
        }
        return itemList;
    }
}
